package com.hmall.mq;

import com.hmall.constants.MqConstants;
import com.hmall.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class HMallListener {
    @Resource
    private SearchService searchService;

    /**
     * 监听酒店新增或修改的业务
     * @param id 酒店id
     */
    @RabbitListener(queues = MqConstants.HMALL_INSERT_QUEUE)
    public void listenHotelInsertOrUpdate(String id){
        log.info("开始插入数据，id：{}",id);

        searchService.insertById(Long.valueOf(id));
        log.info("数据插入成功");

    }

    /**
     * 监听酒店删除的业务
     * @param id 酒店id
     */
    @RabbitListener(queues = MqConstants.HMALL_DELETE_QUEUE)
    public void listenHotelDelete(Long id){
        searchService.deleteById(id);
    }
}
